﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tasker.Composition;
using Tasker.Infrastructure.Entities;
using Tasker.Infrastructure.Services;
using Tasker.WebUI.Models;

namespace Tasker.WebUI.Controllers
{
    public class StaffController : TaskerControllerBase
    {
        //
        // GET: /Staff/
        private IAccountService _account = Resolver.Resolve<IAccountService>();

        public ActionResult Index()
        {
            IEnumerable<IUser> users = _account.SelectAllUsers();

            StaffListModel model = new StaffListModel();
            model.staff = from user in users
                          select new StaffModel()
                                     {
                                         Id = user.Id,
                                         FirstName = user.FirstName,
                                         LastName = user.LastName,
                                         Login = user.Login,
                                         Position = user.Position,
                                         Emails = _account.GetUserEmails(user.Id).Take(1),
                                         Phones = _account.GetUserPhones(user.Id).Take(1)
                                     };

            return View("List", model);
        }

        public ActionResult ShowProfile(int id)
        {
            IUser user = _account.SelectUser(id);
            StaffShowModel model = new StaffShowModel();
            model.FirstName = user.FirstName;
            model.LastName = user.LastName;
            model.Login = user.Login;
            model.Position = user.Position;
            model.Comment = user.Comment;
            model.Emails = _account.GetUserEmails(user.Id);
            model.Phones = _account.GetUserPhones(user.Id);
            model.PictureName = user.PictureName;
            model.PictureType = user.PictureType;

            return View("Profile", model);
        }

    }
}
